import http from "../../utils/http"

export default {
  state: () => ({
    loginUser: null,
    resources: null,
  }),
  mutations: {
    setLoginUser(state, value) {
      state.loginUser = value
    },
    setResources(state, value) {
      state.resources = value
    },
    logout(state) {
      state.loginUser = null
      state.resources = null
      sessionStorage.removeItem('token')
    }
  },
  actions: {
    async getLoginUser({commit}) {
      const result = await http('/api/users/current')
      commit('setLoginUser', result.data)
    },
    async getResources({commit}) {
      const result = await http('/api/users/resources')
      commit('setResources', result.data)
    },
  },
  getters: {}
}
